﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Ket_noi_toi_VPP_bang_mo_hinh_ba_lop.DAL;

namespace Ket_noi_toi_VPP_bang_mo_hinh_ba_lop
{
    public partial class FormHDNhap : Form
    {
        HDNhap HD = new HDNhap();
        public FormHDNhap()
        {
            InitializeComponent();
        }

        private void btThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FormHDNhap_Load(object sender, EventArgs e)
        {
            dtgHienThi.DataSource = HD.SelectAll();
        }

        private void btReset_Click(object sender, EventArgs e)
        {
            this.tbMaHD.Clear();
            this.tbMaNV.Clear();
            this.tbNgayLap.Clear();
            this.tbMaHD.Focus();
        }

        private void btSelect_Click(object sender, EventArgs e)
        {
            dtgHienThi.DataSource = HD.SelectID(Convert.ToInt32(tbMaHD.Text));
        }

        private void btDelete_Click(object sender, EventArgs e)
        {
            HD.Delete(Convert.ToInt32(tbMaHD.Text));
            dtgHienThi.DataSource = HD.SelectAll();
        }

        private void btInsert_Click(object sender, EventArgs e)
        {
            HD.Insert(Convert.ToInt32(tbMaNV.Text), Convert.ToDateTime(tbNgayLap.Text)); 
            dtgHienThi.DataSource = HD.SelectAll();
            FormHDNhap_Load(sender,e);
        }

        private void btUpdate_Click(object sender, EventArgs e)
        {
            HD.Update(Convert.ToInt32(tbMaHD.Text), Convert.ToInt32(tbMaNV.Text), Convert.ToDateTime(tbNgayLap.Text));
            dtgHienThi.DataSource = HD.SelectAll();
            FormHDNhap_Load(sender,e);
        }

        private void dtgHienThi_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            string ID;
            int dong;
            dong = e.RowIndex;
            ID = dtgHienThi.Rows[dong].Cells[2].Value.ToString();
            tbMaHD.Text = dtgHienThi.Rows[dong].Cells[0].Value.ToString();
            tbMaNV.Text = dtgHienThi.Rows[dong].Cells[1].Value.ToString();
            tbNgayLap.Text = dtgHienThi.Rows[dong].Cells[2].Value.ToString();
        }

        private void btGoBack_Click(object sender, EventArgs e)
        {
            FormHDNhap_Load(sender,e);
        }
    }
}
